package com.ruoyi.web.controller.yada;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.system.domain_yada.ThematicMapDomain;
import com.ruoyi.system.service_yada.ThematicMapService;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 专题图模块
 * @author taco chen
 */
@RestController
@RequestMapping(value = "/thematic-map")
@Api(tags = "专题图模块")
public class ThematicMapController {

    @Resource
    private ThematicMapService thematicMapService;

    /**
     * 查询方法
     * @param response 响应头
     * @return 参数类
     */
    @ApiOperation("获取所有专题图")
    @ApiImplicitParams({})
    @ApiResponses({
            @ApiResponse(code =200,message = "请求成功"),
            @ApiResponse(code =401,message = "没有认证"),
            @ApiResponse(code =403,message = "权限不足"),
            @ApiResponse(code =404,message = "未找到")
    })
    @RequestMapping(value = "/get/all",method = {RequestMethod.POST})
    public AjaxResult selectAllThematicMap(HttpServletResponse response,@RequestBody ThematicMapDomain thematicMapDomain)
    {
        List<ThematicMapDomain> res= thematicMapService.selectAll(thematicMapDomain.getPictureType(),
                thematicMapDomain.getPictureTypeOne(),thematicMapDomain.getPictureTypeTwo());
        return AjaxResult.success(res);
    }
    /**
     * 删除方法
     * @param id id
     * @return 状态码
     */
    @RequestMapping(value = "/delete",method = {RequestMethod.DELETE})
    @ApiOperation(value = "删除方法",httpMethod = "DELETE")
    @ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "long", paramType = "path", dataTypeClass = long.class)
    public AjaxResult deleteThematicMap(@Param("id") Long id)
    {
        int num = thematicMapService.deleteById(id);
        if (num>0) {
            return AjaxResult.success();
        }
        return  AjaxResult.error();
    }

    /**
     * 新增方法
     * @param thematicMapDomain 新增实体类
     * @return 状态码
     */
    @ApiOperation(value = "新增方法",httpMethod = "POST")
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public AjaxResult saveThematicMap(@RequestBody ThematicMapDomain thematicMapDomain)
    {


        thematicMapDomain.setCreatedTime(LocalDateTime.now());
        int num = thematicMapService.save(thematicMapDomain);
        if (num>0) {
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }


}
